from flask import Flask,jsonify,request

from common.mysql import mysql
import datetime
from flask_cors import CORS  

app=Flask(__name__)
CORS(app)




@app.route('/insert1',methods=['GET','POST'])
def ceshi1():
    config='config/config.ini'
    sql='MOBILE-APP'
    print('请求已经进来了')
    db = mysql(config_path=config, sql_path=sql)
    chaxun_sql = 'select * from lianxi where id=1'
    result = db.select_one(chaxun_sql)

    # 检查是否有 datetime 对象，并将其转换为字符串格式
    if result:
        result = list(result)  # 将结果转换为可修改的列表
        for index, value in enumerate(result):
            if isinstance(value, datetime.datetime):
                result[index] = value.strftime('%Y-%m-%d %H:%M:%S')  # 格式化 datetime 对象

    return jsonify({"success": True, "data": result})



@app.route('/insert2',methods=['GET','POST'])
def ceshi2():
    data=request.get_json()
    if data:
        return jsonify({'success':True,'data':23})
    else:
        return jsonify({'success':False,'data':3434})
        






if __name__ == '__main__':
    app.run(host='0.0.0.0',debug=True,port=5000,threaded=True)


